/**
* @author wangpeizhi
*/
import request from '@/utils/request'
import getAES from './getAES'

/**
 * 平台端用户自动登录
 * @param {*} UUID
 */
export function loginByKey(UUID) {
  const KEY = getAES // KEY ： 对称加密生成的key和iv  以,隔开
  let data = {
    UUID,
    KEY
  }
  var signStr = JSON.stringify(data)// 仅处理
  data = {
    param: window.$Vue.$getRsaCode(signStr)
  }
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/managerLogin',
    method: 'post',
    data
  })
}
/**
 * 用户登录
 * @param {*} userName
 * @param {*} password
 * @param {*} code
 * @param {*} type
 */
export function loginByPhoneAndPwd(phoneNumber, password) {
  const KEY = getAES // KEY ： 对称加密生成的key和iv  以,隔开
  let data = {
    phoneNumber,
    password,
    KEY
  }
  var signStr = JSON.stringify(data)// 仅处理
  data = {
    param: window.$Vue.$getRsaCode(signStr)
  }
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/loginByPhoneAndPwd',
    method: 'post',
    data
  })
}
// -----新  短信验证码
export function loginByPhone(phoneNumber, smsCode) {
  const KEY = getAES // KEY ： 对称加密生成的key和iv  以,隔开
  let data = {
    phoneNumber,
    smsCode,
    KEY
  }
  var signStr = JSON.stringify(data)// 仅处理
  data = {
    param: window.$Vue.$getRsaCode(signStr)
  }
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/loginByPhoneNumber',
    method: 'post',
    data
  })
}

/**
 * 获取用户信息
 * @param {*} token
 */
export function getUserInfo(token) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: 'backend/sysUserLogin/getUserInfo',
    method: 'get',
    params: { token }
  })
}

/**
 * 找回密码发送手机验证码
 */
export function getPhoneCode(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/sendSmsCode',
    method: 'post',
    data
  })
}

/**
 * 手机号找回密码提交
 */
export function submitPw(obj) {
  var signStr = JSON.stringify(obj)
  const data = {
    param: window.$Vue.$getRsaCode(signStr)
  }
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/loginByPhoneUpdPwd',
    method: 'post',
    data
  })
}

/**
 * 退出登录
 */
export function logout() {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/loginOut',
    method: 'post'
  })
}

/**
 * 获取Title
 */
export function getTopTitle(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/sys/sysConfig/getByNameNoAnnotation',
    method: 'post',
    data
  })
}

/**
 * 获取管理员手机号
 */
export function getPartOfAdminMobileNumber() {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/getPartOfAdminMobileNumber',
    method: 'post'
  })
}

/**
 * 重置管理员密码-发送验证码
 */
export function getAdminPhoneCode(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/sendSmsCodeAdmin',
    method: 'post',
    data
  })
}

/**
 * 重置管理员密码-提交
 */
export function resetAdminPassword(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/resetAdminPassword',
    method: 'post',
    data
  })
}

/**
 * 获取系统名称
 */
export function getDataByType(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/sys/sysConfig/getByNameNoAnnotation',
    method: 'post',
    data
  })
}

/**
 * 获取系统配置
 * @param {*} data
 */
export function getSysconfig(data) {
  return request({
    baseURL: '/API-ENTERPRISE-BACKEND/',
    url: '/backend/sys/sysConfig/getByName',
    method: 'post',
    data
  })
}
